﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>任务分配</title>

    <script type="text/javascript" src="../Scripts/QueryString.js"></script>
    <script type="text/javascript" src="../Scripts/bootstrap/js/jquery.min.js"></script>
    <link href="../../DataUser/Style/ccbpm.css" rel="Stylesheet" />

    <!-- 引用通用的js文件. -->
    <script type="text/javascript"   src="../Scripts/config.js" ></script>
    <script type="text/javascript"   src="../Comm/Gener.js" ></script>
    <script type="text/javascript" language="javascript">

        var workID = GetQueryString("WorkID");

        var nodeID = GetQueryString("FK_Node");
        if (nodeID == undefined || nodeID == null)
            nodeID = GetQueryString("NodeID");


        var gwls = null;
        $(function () {
            //查询出来数据.
            gwls = new Entities("BP.WF.GenerWorkerLists");
            gwls.Retrieve("WorkID", workID, "FK_Node", nodeID);

            //有可能是分合流.
            if (gwls.length == 0)
                gwls.Retrieve("FID", workID, "FK_Node", nodeID);

            var html = "";
            html += "<ul>";
            for (var i = 0; i < gwls.length; i++) {

                var gwl = gwls[i];
                if (gwl.IsEable == 1)
                    html += "<li style='list-style-type:none;'><label><input checked='checked' type=checkbox value='' id='" + gwl.FK_Emp + "' >" + gwl.FK_Emp + "," + gwl.FK_EmpText + "</label></li>";
                else
                    html += "<li style='list-style-type:none;'><label><input type=checkbox value='' id='" + gwl.FK_Emp + "' >" + gwl.FK_Emp + "," + gwl.FK_EmpText + "</label></li>";
            }

            html += "</ul>";

            $("#info").html(html);
        });

        function Save() {
            //获取所有未选中checkbox
            var notChecked = $("input:checkbox").not("input:checked");

            /*
            这里因为wf_GenerWorkerList为多主键(WorkID\FK_Node\FK_Emp),使用一下方法获取对象报错
            var newgwl = new Entity("BP.WF.GenerWorkerList");
            newgwl.Retrieve();//报错
            所有就先获取集合,然后在通过集合的对象进行实例化了,如下
            */
            gwls = new Entities("BP.WF.GenerWorkerLists");
            if (notChecked.size() != 0) {
                $.each(notChecked, function () {
                    gwls.Retrieve("WorkID", workID, "FK_Node", nodeID, "FK_Emp", $(this).attr('id'));
                    var newgwl = new Entity("BP.WF.GenerWorkerList", gwls[0]);
                    newgwl.IsEnable = "0";
                    newgwl.Update();
                });
            }



            //保存状态与路径.
            var webUser = new WebUser();

            var rm = new Entity("BP.WF.RememberMe");
            rm.FK_Emp = webUser.No;
            rm.FK_Node = nodeID;
            rm.SetPKVal(rm.FK_Node + "_" + rm.FK_Emp);
            rm.MyPK = rm.FK_Node + "_" + rm.FK_Emp;

            var obj = "";
            var objExt = "";

            //查询出来数据.
            gwls = new Entities("BP.WF.GenerWorkerLists");
            gwls.Retrieve("WorkID", workID, "FK_Node", nodeID);

            //有可能是分合流.
            if (gwls.length == 0)
                gwls.Retrieve("FID", workID, "FK_Node", nodeID);


            for (var i = 0; i < gwls.length; i++) {

                var gwl = gwls[i];
                if (gwl.IsEnable == 0)
                    continue;

                obj += gwl.FK_Emp + "@";
                objExt += gwl.FK_EmpText + "&nbsp;&nbsp;";
            }
            rm.Objs = obj;
            rm.ObjsExt = objExt;

            //生成如下两个变量.
            var emps = "";
            var empExts = "";
            for (var i = 0; i < gwls.length; i++) {
                var gwl = gwls[i];

                emps += gwl.FK_Emp + "@";

                var empInfo = gwl.FK_Emp + "," + gwl.FK_EmpText;

                if (obj.indexOf(gwl.FK_Emp) != -1)
                    empExts += "<font color=green>" + empInfo + "</font>&nbsp;&nbsp;";
                else
                    empExts += "<strike><font color=red>(" + empInfo + "</font></strike>&nbsp;&nbsp;";
            }

            rm.Emps = emps;
            rm.EmpsExt = empExts;

            rm.Save(); //执行保存.
            alert("分配成功");
        }
    </script>
</head>
<body >

<form id="cc">

<h3>工作分配</h3>

     <div id="info" ></div>

     <input type=button value='执行分配'  onclick='Save()' />

</form>

</body>
</html>
